package com.company.common.core.util;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {

	/**
	 * 获取当前天的开始
	 * @param date
	 * @return
	 */
	public static Date beginOfDate(Date date){

		Calendar cl = Calendar.getInstance();
		cl.setTime(date);
		cl.set(Calendar.HOUR_OF_DAY, 0);
		cl.set(Calendar.MINUTE, 0);
		cl.set(Calendar.SECOND, 0);
		cl.set(Calendar.MILLISECOND, 0);

		return cl.getTime();
	}

	/**
	 * 获取当前天的结束
	 * @param date
	 * @return
	 */
	public static Date endOfDate(Date date){

		Calendar cl = Calendar.getInstance();
		cl.setTime(date);
		cl.set(Calendar.HOUR_OF_DAY, 23);
		cl.set(Calendar.MINUTE, 59);
		cl.set(Calendar.SECOND, 59);
		cl.set(Calendar.MILLISECOND, 999);
		return cl.getTime();
	}
	/**
	 * 根据不同的日期格式返回不同格式的String类型日期
	 * formate 日期格式如：yyyy-MM-dd HH:mm:ss
	*/
     public static String getNowTime (String formate){
    	 //"yyyy-MM-dd HH:mm:ss"
    	 Date now = new Date(); 
		 SimpleDateFormat dateFormat = new SimpleDateFormat(formate);//可以方便地修改日期格式
		 String time = dateFormat.format( now ); 
		 return time;
     }
     
     public static Date getFormatTime(String date,String formatType){
    	SimpleDateFormat sdf = new SimpleDateFormat(formatType);
    	Date date_format = null;
		try {
			date_format = sdf.parse(date);
		} catch (ParseException e) {
			e.printStackTrace();
		}
    	 return date_format;
     }
     
     public static void main(String[] args){
    	 System.out.println(getFormatTime("201506080610", "yyyyMMddHHmm"));//Mon Jun 08 06:10:00 CST 2015
     }
}
